﻿namespace EyeOpen.ViewModel.Silverlight
{
    using System;
    using EyeOpen.UI.Silverlight;

    public class CommandStatus : RelayCommand
    {
        private bool status;

        public CommandStatus(ViewModelBase viewModelBase)
        {
            viewModelBase.Register(this);
        }

        public CommandStatus(ViewModelBase viewModelBase, Action executeMethod, Func<bool> canExecuteMethod)
            : base(executeMethod, canExecuteMethod)
        {
            viewModelBase.Register(this);
        }

        public override bool CanExecute(object parameter)
        {
            status = base.CanExecute(parameter);
            return status;
        }

        public bool CheckCanExecuteChanged(object obj)
        {
            Func<object, bool> canExecuteChanged = base.CanExecute;
            var statusChanged = canExecuteChanged(obj);

            if (statusChanged != status)
            {
                status = statusChanged;
                return true;
            }

            return false;
        }
    }
}
